//
//  JWHUD.m
//  SiqiPlan
//
//  Created by sunjiawen on 2017/5/17.
//  Copyright © 2017年 sjw. All rights reserved.
//

#import "JWHUD.h"

@implementation JWHUD
//成功提示
+ (void)showCompleteMessage:(NSString *)message inView:(UIView *)view{
    [JWHUD showMessageWithMessage:message withImage:@"Checkmark" inView:view];
}
//失败提示
+ (void)showFailMessage:(NSString *)message inView:(UIView *)view{
    [JWHUD showMessageWithMessage:message withImage:@"warn_icon" inView:view];
}
//错误提示
+ (void)showErrorMessage:(NSString *)message inView:(UIView *)view{
    [JWHUD showMessageWithMessage:message withImage:@"close_icon" inView:view];
}

+ (MBProgressHUD *)showGlobalProgressHUDWithTitle:(NSString *)title inView:(UIView *)view {
    [self dismissGlobalHUDInView:view];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.labelText = title;
    
    return hud;
}

+ (void)dismissGlobalHUDInView:(UIView *)view {
    [MBProgressHUD hideHUDForView:view animated:YES];
}

+ (void)showMessageWithMessage:(NSString *)message withImage:(NSString *)imageName inView:(UIView *)view{
    [self dismissGlobalHUDInView:view];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    // Set an image view with a checkmark.
    UIImage *image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    hud.customView = [[UIImageView alloc] initWithImage:image];
    
    // Set custom view mode
    hud.mode = MBProgressHUDModeCustomView;
    hud.labelText = message;

    // Looks a bit nicer if we make it square.
    hud.square = YES;
    // Optional label text.
    [hud hide:YES afterDelay:3.f];
    
}

+ (void)showTextOnly:(NSString *)message inView:(UIView *)view {
    [self dismissGlobalHUDInView:view];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    
    // Set the text mode to show only text.
    hud.mode = MBProgressHUDModeText;
    hud.labelText = message;
    
    [hud hide:YES afterDelay:3.f];
}
@end
